//
//  CommentCell.m
//  Custom_Weibo
//
//  Created by LEO on 12/15/15.
//  Copyright © 2015 Leo_Lei. All rights reserved.
//

#import "CommentCell.h"

@implementation CommentCell

#pragma mark - INITIALIZATION_METHODS
- (void)awakeFromNib {
    _commentLabel = [[WXLabel alloc] initWithFrame:CGRectZero];
    _commentLabel.font = [UIFont systemFontOfSize:14.0f];
    _commentLabel.linespace = 5.0f;
    _commentLabel.wxLabelDelegate = self;
    [self.contentView addSubview:_commentLabel];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    //  User image.
    NSString *userImageString = _commentModel.user.profile_image_url;
    [_userImage sd_setImageWithURL:[NSURL URLWithString:userImageString]];
    
    //  User name.
    _userName.text = _commentModel.user.screen_name;
    
    //  Comment.
    _commentLabel.text = _commentModel.text;
    CGFloat commentHeight = [WXLabel getTextHeight:14.0f
                                             width:240
                                              text:_commentLabel.text
                                         linespace:5.0f];
    _commentLabel.frame = CGRectMake(_userImage.right + 10, _userName.bottom + 5,
                                     kScreenWidth - 70, commentHeight);
}

#pragma mark - WXLABEL_DELEGATE
//  Set different color for special text.
- (NSString *)contentsOfRegexStringWithWXLabel:(WXLabel *)wxLabel {
    NSString *regex1 = @"@\\w+";
    NSString *regex2 = @"http(s)?://([A-Za-z0-9._-]+(/)?)*";
    NSString *regex3 = @"#^#+#";
    
    NSString *regex = [NSString stringWithFormat:@"%@|%@|%@", regex1, regex2, regex3];

    return regex;
}

//  Choose the color for special text.
- (UIColor *)linkColorWithWXLabel:(WXLabel *)wxLabel {
    return kRGB(0, 149, 255, 0.6);
}

//  Choose the color for special text when the text is being pressed.
- (UIColor *)passColorWithWXLabel:(WXLabel *)wxLabel {
    return kRGB(0, 255, 50, 0.6);
}

#pragma mark - CUSTOM_METHODS
+ (CGFloat)getCommentHeight:(CommentModel *)commentModel {
    CGFloat height = [WXLabel getTextHeight:14.0f
                                      width:kScreenWidth - 70
                                       text:commentModel.text
                                  linespace:5.0f];
    
    return height + 40;
}


@end
